package com.company.example.task;


import com.company.example.core.util.DateUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by ywl on 2016/12/26.
 */
@Service
public class XmlTask {
    //按天统计
    public void dayStatistics() {
        Date now = new Date();
        String yearStartDate = DateUtil.formatDateTime(DateUtil.addYears(now, -1), "yyyy-MM-dd");
        String startDatetime = DateUtil.formatDateTime(DateUtil.addDays(now, -1), "yyyy-MM-dd 00:00:00");
        String endDatetime = DateUtil.formatDateTime(DateUtil.addDays(now, -1), "yyyy-MM-dd 23:59:59");
        statisticsData(now,yearStartDate,startDatetime,endDatetime,"day");
    }

    //按周统计
    public void weekStatistics() {
        Date now = new Date();
        String yearStartDate = DateUtil.formatDateTime(DateUtil.addYears(now, -1), "yyyy-MM-dd");
        String startDatetime = DateUtil.formatDateTime(DateUtil.addWeeks(now, -1), "yyyy-MM-dd 00:00:00");
        String endDatetime = DateUtil.formatDateTime(DateUtil.addDays(now, -1), "yyyy-MM-dd 23:59:59");
        statisticsData(now,yearStartDate,startDatetime,endDatetime,"week");
    }

    //按月统计
    public void monthStatistics() {
        Date now = new Date();
        String yearStartDate = DateUtil.formatDateTime(DateUtil.addYears(now, -1), "yyyy-MM-dd");
        String startDatetime = DateUtil.formatDateTime(DateUtil.addMonths(now, -1), "yyyy-MM-dd 00:00:00");
        String endDatetime = DateUtil.formatDateTime(DateUtil.addDays(now, -1), "yyyy-MM-dd 23:59:59");
        statisticsData(now,yearStartDate,startDatetime,endDatetime,"month");
    }

    //按季度统计
    public void quarterStatistics() {
        Date now = new Date();
        String yearStartDate = DateUtil.formatDateTime(DateUtil.addYears(now, -1), "yyyy-MM-dd");
        String startDatetime = DateUtil.formatDateTime(DateUtil.addMonths(now, -3), "yyyy-MM-dd 00:00:00");
        String endDatetime = DateUtil.formatDateTime(DateUtil.addDays(now, -1), "yyyy-MM-dd 23:59:59");
        statisticsData(now,yearStartDate,startDatetime,endDatetime,"quarter");
    }

    //按年统计
    public void yearStatistics() {
        Date now = new Date();
        String yearStartDate = DateUtil.formatDateTime(DateUtil.addYears(now, -1), "yyyy-MM-dd");
        String startDatetime = DateUtil.formatDateTime(DateUtil.addYears(now, -1), "yyyy-MM-dd 00:00:00");
        String endDatetime = DateUtil.formatDateTime(DateUtil.addDays(now, -1), "yyyy-MM-dd 23:59:59");
        statisticsData(now,yearStartDate,startDatetime,endDatetime,"year");
    }

    public void test() {
        Date now = new Date();
        String yearStartDate = DateUtil.formatDateTime(DateUtil.addYears(now, -1), "yyyy-MM-dd");
        String startDatetime = DateUtil.formatDateTime(DateUtil.addDays(now, -1), "yyyy-MM-dd 00:00:00");
        String endDatetime = DateUtil.formatDateTime(DateUtil.addDays(now, -1), "yyyy-MM-dd 23:59:59");
        statisticsData(now,yearStartDate,startDatetime,endDatetime,"test");
    }

    private void statisticsData(Date date,String yearStartDate,String startDatetime,String endDatetime,String type) {
        System.out.println("--------------------------");
        System.out.println("type:"+type);
        System.out.println("date:"+date);
        System.out.println("yearStartDate:"+yearStartDate);
        System.out.println("startDatetime:"+startDatetime);
        System.out.println("endDatetime:"+endDatetime);
        System.out.println("--------------------------");
    }
}
